package com.eclipse.e0112_io.bz案例;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class a从文件读取字节 {

	public static void main(String[] args) {

		File file = new File("/Users/liuzhuangzhuang/iotest/b.txt");
		FileInputStream fileInputStream = null;
		if (file.exists()) {
			try {
				fileInputStream = new FileInputStream(file);

				/*
				 * int byteContext = 0;
				 * 
				 * do { byteContext = fileInputStream.read(); System.out.println(byteContext); }
				 * while (byteContext != -1);
				 */

				int byteNum = 0;

				byte[] byteArray = new byte[3];
				// 11111a1(
				while (byteNum != -1) {
					byteNum = fileInputStream.read(byteArray);
					System.out.println("bytenum:" + byteNum);
					for (int i = 0; i < byteNum; i++) {
						System.out.println(byteArray[i]);
					}

				}
			} catch (Exception ex) {
				ex.printStackTrace();
			} finally {
				try {
					fileInputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}

		} else {
			System.out.println("文件不存在");
		}

	}

}
